package controller

import (
	"admin/model"
	"common/helper"
	"encoding/json"
	"github.com/valyala/fasthttp"
)

type QuoteManage struct{}

type operator_quote_data struct {
	OperatorId          int     `json:"operator_id" cbor:"operator_id"`
	BalanceQuota        float64 `json:"balance_quota" cbor:"balance_quota"`
	BalanceUsed         float64 `json:"balance_used" cbor:"balance_used"`
	CommissionQuota     float64 `json:"commission_quota" cbor:"commission_quota"`
	TestMemberQuota     float64 `json:"test_member_quota" cbor:"test_member_quota"`
	TestMemberUsed      float64 `json:"test_member_used" cbor:"test_member_used"`
	AutoWithdrawalLimit float64 `json:"auto_withdrawal_limit" cbor:"auto_withdrawal_limit"`
}

// /获取运营商额度列表
func (that MemberController) GetOperatorQuoteList(ctx *fasthttp.RequestCtx) {
	param := model.OperatorQuoteParam{}

	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	if param.Page < 1 {
		param.Page = 1
	}
	if param.PageSize < 10 || param.PageSize > 3000 {
		helper.RetData(ctx, false, "参数错误")
		return
	}
	data, err := model.GetOpeartorQuoteList(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, data)
}

// /添加额度明细
func (that MemberController) AddOperatorQuote(ctx *fasthttp.RequestCtx) {
	param := model.AddOperatorQuoteParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	err = model.AddOperatorQuote(param)
	if err != nil {
		helper.RetData(ctx, false, "数据库错误")
	}
	helper.RetData(ctx, true, "成功")
}
